@if (ViewData.ModelState.Any(x => x.Value.Errors.Count > 0))
{
    <script>
    document.addEventListener('DOMContentLoaded', function() {
        @foreach (var error in ViewData.ModelState.SelectMany(x => x.Value.Errors))
        {
            <text>
            Swal.fire({
                icon: 'error',
                title: '操作失败',
                text: '@Html.Raw(error.ErrorMessage)',
                confirmButtonText: '确定',
                confirmButtonColor: '#dc3545'
            });
            </text>
        }
    });
    </script>
}